from django.conf.urls.defaults import *
from django.contrib.auth.decorators import login_required
from models import Domain
from models import Nameserver
from models import Record
from models import Supermaster
from models import Acl
from models import Cryptokey
from models import Domainmetadata
from forms import DomainForm
from forms import NameserverForm
from forms import RecordForm
from forms import SupermasterForm
from forms import AclForm
from forms import CryptokeyForm
from forms import DomainmetadataForm
from django.views.generic.create_update import create_object, update_object, delete_object
from django.views.generic.list_detail import object_list, object_detail
from views import records_csv
from views import view_domain
from views import view_nameserver
from views import view_record
from views import view_supermaster
from views import view_acl
from views import view_cryptokey
from views import view_domainmetadata
from views import search_domain
from views import search_record
from views import search_nameserver
from views import search_supermaster
from views import search_acl
from views import search_cryptokey
from views import search_domainmetadata
from views import add_domain, add_record
from views import edit_domain, edit_record
from django_restapi.model_resource import Collection
from django_restapi.responder import *
from django_restapi.receiver import *

domain_info_dict = {
	'queryset': Domain.objects.all(),
}

domain_xml = Collection(
	queryset = Domain.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = XMLReceiver(),
	responder = XMLResponder(),
)

domain_json = Collection(
	queryset = Domain.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = JSONReceiver(),
	responder = JSONResponder()
)

domain_create_dict = {
	'form_class': DomainForm,
	'post_save_redirect': '/dns/domain/',
}

domain_delete_dict = {
	'model': Domain,
	'post_delete_redirect': '/dns/domain/',
}

nameserver_info_dict = {
	'queryset': Nameserver.objects.all()
}

nameserver_xml = Collection(
	queryset = Nameserver.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = XMLReceiver(),
	responder = XMLResponder(),
)

nameserver_json = Collection(
	queryset = Nameserver.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = JSONReceiver(),
	responder = JSONResponder()
)

nameserver_create_dict = {
	'form_class': NameserverForm,
	'post_save_redirect': '/dns/nameserver/',
}

nameserver_delete_dict = {
	'model': Nameserver,
	'post_delete_redirect': '/dns/nameserver/',
}

record_info_dict = {
	'queryset': Record.objects.all()
}

record_xml = Collection(
	queryset = Record.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = XMLReceiver(),
	responder = XMLResponder(),
)

record_json = Collection(
	queryset = Record.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = JSONReceiver(),
	responder = JSONResponder()
)

record_create_dict = {
	'form_class': RecordForm,
	'post_save_redirect': '/dns/record/',
}

record_delete_dict = {
	'model': Record,
	'post_delete_redirect': '/dns/record/',
}

supermaster_info_dict = {
	'queryset': Supermaster.objects.all()
}

supermaster_xml = Collection(
	queryset = Supermaster.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = XMLReceiver(),
	responder = XMLResponder(),
)

supermaster_json = Collection(
	queryset = Supermaster.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = JSONReceiver(),
	responder = JSONResponder()
)

supermaster_create_dict = {
	'form_class': SupermasterForm,
	'post_save_redirect': '/dns/supermaster/',
}

supermaster_delete_dict = {
	'model': Supermaster,
	'post_delete_redirect': '/dns/supermaster/',
}

acl_info_dict = {
	'queryset': Acl.objects.all()
}

acl_xml = Collection(
	queryset = Acl.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = XMLReceiver(),
	responder = XMLResponder(),
)

acl_json = Collection(
	queryset = Acl.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = JSONReceiver(),
	responder = JSONResponder()
)

acl_create_dict = {
	'form_class': AclForm,
	'post_save_redirect': '/dns/acl/',
}

acl_delete_dict = {
	'model': Acl,
	'post_delete_redirect': '/dns/acl/',
}

cryptokey_info_dict = {
	'queryset': Cryptokey.objects.all()
}

cryptokey_xml = Collection(
	queryset = Cryptokey.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = XMLReceiver(),
	responder = XMLResponder(),
)

cryptokey_json = Collection(
	queryset = Cryptokey.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = JSONReceiver(),
	responder = JSONResponder()
)

cryptokey_create_dict = {
	'form_class': CryptokeyForm,
	'post_save_redirect': '/dns/cryptokey/',
}

cryptokey_delete_dict = {
	'model': Cryptokey,
	'post_delete_redirect': '/dns/cryptokey/',
}

domainmetadata_info_dict = {
	'queryset': Domainmetadata.objects.all()
}

domainmetadata_xml = Collection(
	queryset = Domainmetadata.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = XMLReceiver(),
	responder = XMLResponder(),
)

domainmetadata_json = Collection(
	queryset = Domainmetadata.objects.all(),
	permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
	receiver = JSONReceiver(),
	responder = JSONResponder()
)

domainmetadata_create_dict = {
	'form_class': DomainmetadataForm,
	'post_save_redirect': '/dns/domainmetadata/',
}

domainmetadata_delete_dict = {
	'model': Domainmetadata,
	'post_delete_redirect': '/dns/domainmetadata/',
}

urlpatterns = patterns(
	'',
	(r'^domain/$', login_required(object_list), domain_info_dict),
	(r'^domain/xml/(?P<object_id>[0-9]+)/$', domain_xml),
	(r'^domain/json/(?P<object_id>[0-9]+)/$', domain_json),
	(r'^domain/(?P<object_id>[0-9]+)/$', login_required(view_domain)),
	(r'^domain/add/$', login_required(add_domain)),
	(r'^domain/edit/(?P<object_id>[0-9]+)/$', login_required(edit_domain)),
	(r'^domain/edit/$', login_required(object_list), domain_info_dict),
	(r'^domain/delete/(?P<object_id>[0-9]+)/$', login_required(delete_object), domain_delete_dict),
	(r'^domain/delete/$', login_required(object_list), domain_info_dict),
	(r'^domain/search/$', login_required(search_domain)),
	(r'^nameserver/$', login_required(object_list), nameserver_info_dict),
	(r'^nameserver/xml/(?P<object_id>[0-9]+)/$', nameserver_xml),
	(r'^nameserver/json/(?P<object_id>[0-9]+)/$', nameserver_json),
	(r'^nameserver/(?P<object_id>[0-9]+)/$', login_required(view_nameserver)),
	(r'^nameserver/add/$', login_required(create_object), nameserver_create_dict),
	(r'^nameserver/edit/(?P<object_id>[0-9]+)/$', login_required(update_object), nameserver_create_dict),
	(r'^nameserver/edit/$', login_required(object_list), nameserver_info_dict),
	(r'^nameserver/delete/(?P<object_id>[0-9]+)/$', login_required(delete_object), nameserver_delete_dict),
	(r'^nameserver/delete/$', login_required(object_list), nameserver_info_dict),
	(r'^nameserver/search/$', login_required(search_nameserver)),
	(r'^record/$', login_required(object_list), record_info_dict),
	(r'^record/xml/(?P<object_id>[0-9]+)/$',record_xml),
	(r'^record/json/(?P<object_id>[0-9]+)/$',record_json),
	(r'^record/csv/$', login_required(records_csv)),
	(r'^record/(?P<object_id>[0-9]+)/$', login_required(view_record)),
	(r'^record/add/$', login_required(add_record)),
	(r'^record/edit/(?P<object_id>[0-9]+)/$', login_required(edit_record)),
	(r'^record/edit/$', login_required(object_list), record_info_dict),
	(r'^record/delete/(?P<object_id>[0-9]+)/$', login_required(delete_object), record_delete_dict),
	(r'^record/delete/$', login_required(object_list), record_info_dict),
	(r'^record/search/$', login_required(search_record)),
	(r'^supermaster/$', login_required(object_list), supermaster_info_dict),
	(r'^supermaster/xml/(?P<object_id>[0-9]+)/$', supermaster_xml),
	(r'^supermaster/json/(?P<object_id>[0-9]+)/$', supermaster_json),
	(r'^supermaster/(?P<object_id>[0-9]+)/$', login_required(view_supermaster)),
	(r'^supermaster/add/$', login_required(create_object), supermaster_create_dict),
	(r'^supermaster/edit/(?P<object_id>[0-9]+)/$', login_required(update_object), supermaster_create_dict),
	(r'^supermaster/edit/$', login_required(object_list), supermaster_info_dict),
	(r'^supermaster/delete/(?P<object_id>[0-9]+)/$', login_required(delete_object), supermaster_delete_dict),
	(r'^supermaster/delete/$', login_required(object_list), supermaster_info_dict),
	(r'^supermaster/search/$', login_required(search_supermaster)),
	(r'^acl/$', login_required(object_list), acl_info_dict),
	(r'^acl/xml/(?P<object_id>[0-9]+)/$', acl_xml),
	(r'^acl/json/(?P<object_id>[0-9]+)/$', acl_json),
	(r'^acl/(?P<object_id>[0-9]+)/$', login_required(view_acl)),
	(r'^acl/add/$', login_required(create_object), acl_create_dict),
	(r'^acl/edit/(?P<object_id>[0-9]+)/$', login_required(update_object), acl_create_dict),
	(r'^acl/edit/$', login_required(object_list), acl_info_dict),
	(r'^acl/delete/(?P<object_id>[0-9]+)/$', login_required(delete_object), acl_delete_dict),
	(r'^acl/delete/$', login_required(object_list), acl_info_dict),
	(r'^acl/search/$', login_required(search_acl)),
	(r'^cryptokey/$', login_required(object_list), cryptokey_info_dict),
	(r'^cryptokey/xml/(?P<object_id>[0-9]+)/$', cryptokey_xml),
	(r'^cryptokey/json/(?P<object_id>[0-9]+)/$', cryptokey_json),
	(r'^cryptokey/(?P<object_id>[0-9]+)/$', login_required(view_cryptokey)),
	(r'^cryptokey/add/$', login_required(create_object), cryptokey_create_dict),
	(r'^cryptokey/edit/(?P<object_id>[0-9]+)/$', login_required(update_object), cryptokey_create_dict),
	(r'^cryptokey/edit/$', login_required(object_list), cryptokey_info_dict),
	(r'^cryptokey/delete/(?P<object_id>[0-9]+)/$', login_required(delete_object), cryptokey_delete_dict),
	(r'^cryptokey/delete/$', login_required(object_list), cryptokey_info_dict),
	(r'^cryptokey/search/$', login_required(search_cryptokey)),
	(r'^domainmetadata/$', login_required(object_list), domainmetadata_info_dict),
	(r'^domainmetadata/xml/(?P<object_id>[0-9]+)/$', domainmetadata_xml),
	(r'^domainmetadata/json/(?P<object_id>[0-9]+)/$', domainmetadata_json),
	(r'^domainmetadata/(?P<object_id>[0-9]+)/$', login_required(view_domainmetadata)),
	(r'^domainmetadata/add/$', login_required(create_object), domainmetadata_create_dict),
	(r'^domainmetadata/edit/(?P<object_id>[0-9]+)/$', login_required(update_object), domainmetadata_create_dict),
	(r'^domainmetadata/edit/$', login_required(object_list), domainmetadata_info_dict),
	(r'^domainmetadata/delete/(?P<object_id>[0-9]+)/$', login_required(delete_object), domainmetadata_delete_dict),
	(r'^domainmetadata/delete/$', login_required(object_list), domainmetadata_info_dict),
	(r'^domainmetadata/search/$', login_required(search_domainmetadata)),
)
